/*
 *     Prionace - A file navigator to manage your files
 *
 *     Copyright (C) 2012 Francivan Bezerra
 *
 *     This file is part of Prionace.
 *
 *     Prionace is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     Prionace is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with Prionace.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fba.prionace.file;

import java.awt.FlowLayout;
import java.io.File;
import java.text.DateFormat;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

public class FileExistsDialog extends JPanel {

	private File source;

	private File dest;

	public FileExistsDialog(File source, File dest) {
		setSource(source);
		setDest(dest);
		init();
	}

	private void init() {
		StringBuffer message;
		JFile sourceFile = new JFile(source);
		JFile destFile = new JFile(dest);
		DateFormat dateFormat = DateFormat.getDateTimeInstance(
				DateFormat.SHORT, DateFormat.SHORT);
		JLabel header = new JLabel("<html><b>Já existe um arquivo com o nome "
				+ dest.getName() + "</b></html>");
		JPanel buttonsPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));

		message = new StringBuffer();
		message.append("<html><b>Substituir:</b><br>");
		message.append(dest.getName());
		message.append("<br>Tamanho: ");
		message.append(destFile.getHumanReadableSize());
		message.append("<br>Modificado em: ");
		message.append(dateFormat.format(dest.lastModified()));
		message.append("</html>");
		destFile.setText(message.toString());
		destFile.setToolTipText(null);
		destFile.setHorizontalTextPosition(SwingConstants.RIGHT);
		destFile.setVerticalTextPosition(SwingConstants.CENTER);
		destFile.removeChangeListener(sourceFile);

		message = new StringBuffer();
		message.append("<html><b>Por:</b><br>");
		message.append(source.getName());
		message.append("<br>Tamanho: ");
		message.append(sourceFile.getHumanReadableSize());
		message.append("<br>Modificado em: ");
		message.append(dateFormat.format(source.lastModified()));
		message.append("</html>");
		sourceFile.setText(message.toString());
		sourceFile.setToolTipText(null);
		sourceFile.setHorizontalTextPosition(SwingConstants.RIGHT);
		sourceFile.setVerticalTextPosition(SwingConstants.CENTER);
		sourceFile.removeChangeListener(sourceFile);

		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		add(header);
		add(destFile);
		add(sourceFile);
		add(buttonsPane);
	}

	public File getSource() {
		return source;
	}

	public void setSource(File source) {
		this.source = source;
	}

	public File getDest() {
		return dest;
	}

	public void setDest(File dest) {
		this.dest = dest;
	}
}
